<?php $edit_layout = ($this->Membership_model->is_owner($bricabox->id)
						&& strpos($this->uri->uri_string(), 'edit_layout') !== false) ? true : false; ?>


<?php
if ($this->Membership_model->is_owner($bricabox->id)):
	if ($edit_layout):
?>
<div id="edit_layout">
	<a class="on" href="/<?php if (strpos($this->uri->uri_string(), 'content') !== false) echo "content/{$content->id}"; ?>">I'm finished editing this page's layout</a>
</div>
<?php
	elseif (false):
?>
<div id="edit_layout">
	<a href="<?php if ($this->uri->uri_string() != "") echo '/'.$this->uri->uri_string(); ?>/edit_layout">Edit the layout of this page</a>
</div>
<?php
	endif;
endif;
?>

<?php if ($edit_layout): ?>
<div class="clearfix"></div>
<div id="block_catalog">
	<?php foreach ($avail_blocks->result() as $avail_block): ?>
	<div id="add_block_<?php echo $avail_block->id; ?>" class="add_block">
		<?php echo $avail_block->title; ?>
	</div>
	
	<script type="text/javascript" charset="utf-8">
		$('#add_block_<?php echo $avail_block->id; ?>').Draggable({
			revert: 	true,
			floats:		true,
			ghosting: 	true
		});
	</script>
	<?php endforeach; ?>
</div>
<?php endif; ?>
						
						
						
						
						
						
						
						
						

<?php if ($edit_layout): ?>
<script type="text/javascript" charset="utf-8">
	function editTitle(id)
	{
		var el	  = $('#block_instance_'+id+' h3 span.title');
		var title = el.attr('innerHTML');
		var new_t = prompt('Rename this block:', title);
		
		if (new_t != null)
		{
			// didn't hit cancel
			$.post('/bricabox/<?php echo $bricabox->id; ?>/save_title', {id: id, title: new_t});
			el.attr('innerHTML', new_t);
		}
		return false;
	}
	
	function removeBlock(id)
	{
		if (confirm('Are you sure you want to remove this block? You\'ll lose any custom settings for it. This cannot be undone.'))
		{
			$.post('/bricabox/<?php echo $bricabox->id; ?>/remove_block', {id: id});
			$('#block_instance_'+id).hide().remove();
		}
		return false;
	}
	
	function setExclusion(id, ct_id)
	{
		var el = $('#exclude_'+id+'_'+ct_id);
		if (el.attr('checked') == true)
			var val = "1";
		else
			var val = "0";
		
		$.post('/bricabox/<?php echo $bricabox->id; ?>/toggle_exclusion', {id: id, type_id: ct_id, value: val});
	}
</script>
<?php endif; ?>						